﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.BusinessEntities;
using DataAccess;
using DataAccess.Services;

namespace Inventory.BusinessEntities
{
    public class InventoryRequest
    {
        public InventoryRequest()
        {
            this.ProductIdType = ProductIdType.IndividualProduct;
            this.StoreNumberType = StoreNumberType.IndividualStore;
        }

        public int ProductId { get; set; }

        public ProductIdType ProductIdType { get; set; }

        public int StoreNumber { get; set; }

        public StoreNumberType StoreNumberType { get; set; }

        public IEnumerable<int> GetProductIdsToFind(User userEntity)
        {
            IEnumerable<int> productsToFind;
            if (this.ProductIdType == ProductIdType.AllUsersProducts)
            {
                productsToFind = from p in userEntity.Products select p.Id;
            }
            else
            {
                productsToFind = new int[] { this.ProductId };
            }

            return productsToFind;
        }

        public IEnumerable<int> GetStoreNumbersToFind(IDomainContext domainContext, User userEntity)
        {
            IEnumerable<int> storeIds;
            if (this.StoreNumberType == StoreNumberType.AllStores)
            {
                storeIds = from s in domainContext.Stores select s.Id;
            }
            else
            {
                if (this.StoreNumberType == StoreNumberType.AllUsersStores)
                {
                    storeIds = from s in userEntity.Stores select s.Id;
                }
                else
                {
                    storeIds = new int[] { this.StoreNumber };
                }
            }

            return storeIds;
        }
    }
}